﻿using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class YuanlinUserControl : BaseUserControl
    {
        protected YuanlinUser CurrentUser
        {
            get
            {
                return HttpContext.Current.User as YuanlinUser;
            }
        }

        protected int UserIdFromGreenNum
        {
            get
            {
                string greenNum = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.GreenNum);
                if (!string.IsNullOrEmpty(greenNum))
                {
                    Member member = MemberManager.GetMember(greenNum);
                    if (member != null)
                    {
                        return UserManager.GetUser(member.MemberId).EntityId.Value;
                    }
                }
                return 0;
            }
        }

        protected bool ValidatePermission(PermissionType permission)
        {
            return CurrentUser.GetPermissions().ValidatePermission((long)permission);
        }
        protected bool ValidatePermission(PermissionType permission, Entity entity)
        {
            return CurrentUser.GetPermissions(entity).ValidatePermission((long)permission);
        }
    }
}